package com.lxj.controller.bus;

import com.lxj.common.Result;
import com.lxj.domain.BusCar;
import com.lxj.dto.BusCarDto;
import com.lxj.service.CarService;
import com.lxj.vo.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lxj
 * @date 2021/6/21 9:43
 * @Description:
 */
@RestController
@RequestMapping("/buscar")
public class BusCarController {

    @Autowired
    private CarService carService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/findByPage.do")
    @RequiresPermissions(value = "car:list")
    public Result findByPage(BusCarDto dto){
        PageInfo<BusCar> pageInfo = carService.findByPage(dto);
        return new Result(pageInfo);
    }

    /**
     * 新增
     * @param dto
     * @return
     */
    @PostMapping("/add.do")
    @RequiresPermissions(value = "car:add")
    public Result add(@RequestBody BusCarDto dto){
        return carService.add(dto);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/delete.do/{ids}")
    @RequiresPermissions(value = "car:delete")
    public Result batchDelete(@PathVariable("ids") Integer[] ids){
        return carService.batchDelete(ids);
    }

    /**
     * 修改
     * @param dto
     * @return
     */
    @PostMapping("/update.do")
    @RequiresPermissions(value = "car:update")
    public Result update(@RequestBody BusCarDto dto){
        return carService.updateById(dto);
    }

    /**
     * 租车
     * @param carId
     * @param idCard
     * @param startTime
     * @param endTime
     * @return
     */
    @PostMapping("/rent.do")
    public Result rentCar(Integer carId,String idCard,String startTime ,String endTime){
        return carService.rentCar(carId ,idCard,startTime,endTime) ;
    }
}
